package testcase.app;

import common.Host;
import common.TestData;
import org.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import api.app.GetAPIAccountInfo;

/**
 * 帮忙医APP用户登录接口GetAPIAccountInfo测试用例
 * @author WuZF
 *
 */
public class TestGetAPIAccountInfo
{
	/**
	 * 帮忙医APP用户登录接口GetAPIAccountInfo测试测试环境数据驱动
	 * @return 测试数据
	 * @throws Exception
	 */
	@DataProvider (name = "Test")
	public static String[][] testGetAPIAccountInfoDataProvider() throws Exception
	{
		Host.setup("Test");
		TestData td = new TestData("app/TestGetAPIAccountInfo.xml");
		return td.getParam();	
	}
	
	/**
	 * 帮忙医APP用户登录接口GetAPIAccountInfo生产环境数据驱动
	 * @return 测试数据
	 * @throws Exception
	 */
	@DataProvider (name = "Prod")
	public static String[][] prodGetAPIAccountInfoDataProvider() throws Exception
	{
		Host.setup("Prod");
		TestData td = new TestData("app/TestGetAPIAccountInfo.xml");
		return td.getParam();	
	}
	
	/**
	 * 帮忙医APP用户登录接口GetAPIAccountInfo测试环境用例
	 * @param caseName - 用例名称
	 * @param userAccount - 账号
	 * @param password - 密码
	 * @throws Exception
	 */
	@Test (dataProvider = "Test", groups = {"Test"})
	public void testGetAPIAccountInfoTestCase(String caseName, String userAccount, String password) throws Exception
	{
		String result = GetAPIAccountInfo.post(userAccount, password);
		
		JSONObject jsonResult;
		if (result==null || result.isEmpty())
		{
			jsonResult = null;
		}
		else
		{
			jsonResult = new JSONObject(result);
		}

		//设置检查点
		String checkpoint;
		switch (caseName) {
		case "LoginSuccess":
			checkpoint = jsonResult.getString("Loginstatus");
			Assert.assertEquals(checkpoint,"Success");	//接口返回状态为Success
			break;
		case "PasswordError":
			checkpoint = jsonResult.getString("Loginstatus");
			Assert.assertEquals(checkpoint,"Fail");	//接口返回状态为Fail
			break;
		case "UserAccountError":
			checkpoint = jsonResult.getString("Loginstatus");
			Assert.assertEquals(checkpoint,"Fail");	//接口返回状态为Fail
			break;
		case "UserAccountNull":	
			Assert.assertTrue(result.isEmpty());	//接口返回是否为空
			break;
		case "PasswordNull":
			checkpoint = jsonResult.getString("Loginstatus");
			Assert.assertEquals(checkpoint,"Fail");	//接口返回状态为Fail
			break;
		default:
			break;
		}
	}
	
	/**
	 * 帮忙医APP用户登录接口GetAPIAccountInfo测试生产环境用例
	 * @param caseName - 用例名称
	 * @param userAccount - 账号
	 * @param password - 密码
	 * @throws Exception
	 */
	@Test (dataProvider = "Prod", groups = {"Prod"})
	public void prodGetAPIAccountInfoTestCase(String caseName, String userAccount, String password) throws Exception
	{
		String result = GetAPIAccountInfo.post(userAccount, password); 
		
		JSONObject jsonResult;
		if (!result.isEmpty())
		{
			jsonResult = new JSONObject(result);
		}
		else
		{
			jsonResult = null;
		}

		//检查点：checkpoint
		String checkpoint;
		switch (caseName) {
		case "LoginSuccess":
			checkpoint = jsonResult.getString("Loginstatus");
			Assert.assertEquals(checkpoint,"Success");	//接口返回状态为Success
			break;
		case "PasswordError":
			checkpoint = jsonResult.getString("Loginstatus");
			Assert.assertEquals(checkpoint,"Fail");	//接口返回状态为Fail
			break;
		case "AccountError":
			checkpoint = jsonResult.getString("Loginstatus");
			Assert.assertEquals(checkpoint,"Fail");	//接口返回状态为Fail
			break;
		case "UserAccountNull":	
			Assert.assertTrue(result.isEmpty());	//接口返回是否为空
			break;
		case "PasswordNull":
			checkpoint = jsonResult.getString("Loginstatus");
			Assert.assertEquals(checkpoint,"Fail");	//接口返回状态为Fail
			break;
		default:
			break;
		}

	}

}
